'''
Description: 
Author: notplus
Date: 2021-12-09 10:17:43
LastEditors: notplus
LastEditTime: 2021-12-09 14:24:45
FilePath: /utils.py

Copyright (c) 2021 notplus
'''

import math

def compute_dist(record_a, record_b):
    earth_radius = 6378137
    rad = math.pi / 180.0
    radlat1 = record_a.lat * rad
    radlat2 = record_b.lat * rad
    a = radlat1 - radlat2
    b = (record_a.lng - record_b.lng)*rad
    s = 2*math.asin(math.sqrt(math.pow(math.sin(a/2), 2) +
                              math.cos(radlat1)*math.cos(radlat2)*math.pow(math.sin(b/2), 2)))
    s = s*earth_radius
    s = round(s * 100) / 100
    return s

# from geopy.distance import geodesic
# def compute_dist(record_a, record_b):
#     return geodesic((record_a.lat, record_a.lng), (record_b.lat, record_b.lng)).m


def compute_mean_lat_lng(records):
    sum_lat = 0
    sum_lng = 0

    for rec in records:
        sum_lat += rec.lat
        sum_lng += rec.lng

    return sum_lat / len(records), sum_lng / len(records)
